#include "memento.h"

void Player::showStatus()
{
    std::cout << "血量:" << m_blood << ",魔法值:" << m_magic << ",攻击力:" << m_attack << std::endl;
}

std::shared_ptr<PlayMemento> Player::StorePlayerFile()
{
    return std::make_shared<PlayMemento>(m_blood,m_magic,m_attack);
}

void Player::ReadPlayFile(std::shared_ptr<PlayMemento> memento) 
{
    m_blood = memento->getBlood();
    m_magic = memento->getMagic();
    m_attack = memento->getAttack();
}

void PlayManager::setPlayMemento(uint16_t time, std::shared_ptr<PlayMemento> playmemento)
{
    std::cout << "store file,current timestamp:" << time << std::endl;
    m_time_memento_map.emplace(time,playmemento);
}

std::shared_ptr<PlayMemento> PlayManager::getPlayMemento(uint16_t time)
{
    std::cout << "read file,timestamp:" << time << std::endl;
    auto it =  m_time_memento_map.find(time);
    if(it == m_time_memento_map.end())
    {
        std::cout << "not found file,timestamp:" << time << std::endl;
        return nullptr;
    }    
    else
        return it->second;
}
